package com.ruibang.glass.quality.controller;

import com.ruibang.glass.quality.domain.req.DefectReq;
import com.ruibang.glass.quality.entity.Defect;
import com.ruibang.glass.quality.service.DefectService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @Author: songJinKang
 * @CreateTime: 2023-08-30  14:16
 * @Description: TODO:缺陷控制器
 * @Version: 1.0
 */

@RestController
@RequestMapping("/api/defect")
@Api(value = "缺陷控制器", tags = {"缺陷控制器"})
public class DefectController {

    @Autowired
    private DefectService defectService;

    @GetMapping("/getDetail/{defectId}")
    @ApiOperation(value = "根据id获取详情", notes = "根据id获取详情")
    public ResultBody getDetail(@PathVariable String defectId) {
        return ResultBody.success(defectService.getById(defectId));
    }

    @PostMapping("/queryDefect")
    @ApiOperation(value = "查询缺陷", notes = "查询缺陷")
    public ResultBody queryDefect(@RequestBody DefectReq defectReq) {
        return defectService.queryDefect(defectReq);
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增缺陷", notes = "新增缺陷")
    public ResultBody save(@RequestBody @Valid Defect defect) {
        return defectService.insert(defect);
    }

    @DeleteMapping("/deleteById/{defectId}")
    @ApiOperation(value = "根据id删除缺陷", notes = "根据id删除缺陷")
    public ResultBody deleteById(@PathVariable String defectId) {
        defectService.removeById(defectId);
        return ResultBody.success();
    }

    @PutMapping("/update")
    @ApiOperation(value = "更新缺陷", notes = "更新缺陷")
    public ResultBody deleteById(@RequestBody @Valid Defect defect) {
        defectService.updateById(defect);
        return ResultBody.success();
    }

    @GetMapping("/getDefectList")
    @ApiOperation(value = "获取缺陷列表", notes = "获取缺陷列表")
    public ResultBody getDefectList() {
        return ResultBody.success(defectService.getDefectList());
    }
}
